﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ClipperBaseUI.Controls;
using Clipper.BLL;

namespace Clipper.DataManage
{
    /// <summary>
    /// WinQCReference.xaml 的交互逻辑
    /// </summary>
    public partial class WinQCReferenceInput : BaseWindow
    {
        public WinQCReferenceInput()
        {
            InitializeComponent();
        }

        private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            BLL.DetectItems DetectItems = new DetectItems();
            if (BaseServiceProvider.InputName == Model.InputEnum.Update)
            {
                DetectItem.ItemsSource = DetectItems.GetModelList("");
                Model.QCReference model = BaseServiceProvider.DataModel as Model.QCReference;
                if (model != null)
                {
                    DetectItem.IsEnabled = false;
                    DataContext = model;

                }
            }
            else
            {
                DetectItem.ItemsSource = DetectItems.GetQCReferenceList();
            }
        }
        public void winQcReferenceInput_Activated(object sender, EventArgs e)
        {

        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            bool result = true;
            if (Check())
            {
                Clipper.Model.QCReference model = new Clipper.Model.QCReference();
                Clipper.BLL.QCReference d = new BLL.QCReference();
                model.DetectItem = Convert.ToString(DetectItem.SelectedValue);
                model.chromeTop1 = Convert.ToDecimal(chromeTop1.Text);
                model.chromeLow1 = Convert.ToDecimal(chromeLow1.Text);
                model.chromeTop2 = Convert.ToDecimal(chromeTop2.Text);
                model.chromeLow2 = Convert.ToDecimal(chromeLow2.Text);
                model.chromeMean1 = Convert.ToDecimal(chromeMean1.Text);
                model.standardDeviation1 = Convert.ToDecimal(standardDeviation1.Text);
                model.chromeMean2 = Convert.ToDecimal(chromeMean2.Text);
                model.standardDeviation2 = Convert.ToDecimal(standardDeviation2.Text);
                if (BaseServiceProvider.InputName == Model.InputEnum.Add)
                {
                    result=d.Add(model);
                }
                else
                {
                    result=d.Update(model);
                }
                
                    this.DialogResult = result;
                
            }
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = null;
            Close();
        }

        private bool Check()
        {
            List<string> strErr = new List<string>();
            if (DetectItem.SelectedIndex < 0)
            {
                strErr.Add("DetectItemsNotNullTip");//项目型不能为空！\n
            }

            if (string.IsNullOrEmpty(chromeTop1.Text))
            {
                strErr.Add("ChromeTop1NotNullTip");//"质控1浓度上限不能为空！\n"
            }

            if (string.IsNullOrEmpty(chromeLow1.Text))
            {
                strErr.Add("ChromeLow1NotNullTip");//质控1浓度下限不能为空！\n
            }

            if (string.IsNullOrEmpty(chromeTop2.Text))
            {
                strErr.Add("ChromeTop2NotNullTip"); //质控2浓度上限不能为空！\n  
            }

            if (string.IsNullOrEmpty(chromeLow2.Text))
            {
                strErr.Add("ChromeLow2NotNullTip"); //质控2浓度下限不能为空！\n  
            }

            if (string.IsNullOrEmpty(chromeMean1.Text))
            {
                strErr.Add("ChromeMean1NotNullTip"); //质控1浓度均值不能为空！\n  
            }

            if (string.IsNullOrEmpty(standardDeviation1.Text))
            {
                strErr.Add("StandardDeviation1NotNullTip"); //质控1浓度标准差不能为空！\n  
            }

            if (string.IsNullOrEmpty(chromeMean2.Text))
            {
                strErr.Add("ChromeMean2NotNullTip"); //质控2浓度均值不能为空！\n  
            }

            if (string.IsNullOrEmpty(standardDeviation2.Text))
            {
                strErr.Add("StandardDeviation2NotNullTip"); //质控2浓度标准差不能为空！\n  
            }

            if (strErr.Count>0)
            {
                UIHelper.ShowKeyMessage(strErr);
                return false;
            }

            return true;

        }

    }
}